package com.my.hotel.service.impl;

import com.my.hotel.entity.User;
import com.my.hotel.entity.UserRole;
import com.my.hotel.mapper.UserMapper;
import com.my.hotel.mapper.UserRoleMapper;
import com.my.hotel.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserRoleMapper userRoleMapper;

    public List<User> getList() {
        return userMapper.getList();
    }

    public void addUser(User user){
        userMapper.addUser(user);
    }

    public void delUser(int id) {
        userMapper.delUser(id);
    }

    public User getUserById(int id) {
        return userMapper.getUserById(id);
    }

    public void updateUser(User user) {
        userMapper.updateUser(user);
    }

    public void addUserRole(List<UserRole> list) {
        //添加用户关联角色数据之前 需要先删除用户关联角色的所有数据
        userRoleMapper.delUserRole(list.get(0).getUserId());
        userRoleMapper.addUserRole(list);
    }

    public User getUserByUserName(String username) {
        return userMapper.getUserByUserName(username);
    }

    public List<Map> getGender() {
        return userMapper.getGender();
    }

    public void addBatchUser(List<User> list) {
        userMapper.addBatchUser(list);
    }
}
